<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>employ</title>
    <link rel="stylesheet" href="css/main.css">
</head>
<body>
    <div class="header"></div>
    <div>
        <div>
            <div></div>
            <div class="employ employPage1">
                <div class="lineContainer">
                    <div class="l1"></div>
                    <div class="l2"></div>
                    <div class="l3"></div>
                    <div class="l4"></div>
                    <div class="l5"></div>
                    <div class="l6"></div>
                    <div class="l7"></div>
                    <div class="l8"></div>
                    <div class="l9"></div>
                    <div class="l10"></div>
                    <div class="l11"></div>
                    <div class="l12"></div>
                    <span>万丈光芒哇</span>
                </div>
            </div>
            <div class="employ employPage2">
                <div class="circle">
                    <div class="c1"></div>
                    <div class="c2"></div>
                    <div class="c3"></div>
                </div>
            </div>
            <div class="employ employPage3">
                <div class="m1"></div>
                <div class="m2"></div>
                <div class="m3"></div>
                <div class="m4"></div>
                <div class="m5"></div>
                <div class="m6"></div>
                <div class="m7"></div>
            </div>
            <div class="employ employPage4">
                <canvas width="1160" height="200"></canvas>
            </div>
        </div>
    </div>
    <div class="footer"></div>
</body>
<script src="util/jquery1.9.1.min.js"></script>
<script src="js/main.js"></script>
<script>
    $(function(){
        // 提取头部
        aClick(5);


        // canvas动画，直线变折线运动，将注视去掉就可以看到效果
        function Ball(x, y) {
            this.x = x;
            this.y = y;
            this.radius = 50;
            this.vx = 10;
            this.vy = 0;
        }

        var canvas = document.querySelector('canvas'),
        ctx = canvas.getContext('2d'),
        // W = canvas.width = window.innerWidth,
        // H = canvas.height = window.innerHeight,
        W = canvas.width=canvas.parentNode.offsetWidth,
        H = canvas.height=canvas.parentNode.offsetHeight,
        points = {
            firstRow: [],
            secondRow: [],
            thirdRow: [],
            fourthRow: [],
            fifthRow: [],
            sixthRow: [],
            seventhRow: []
        },
        curves = [],
        ball1 = new Ball(W, H / 2);

        $(window).resize(function(){
            W = canvas.width=canvas.parentNode.offsetWidth;
            H = canvas.height=canvas.parentNode.offsetHeight;
        })

        function generatePoints() {
            var y;
            for (var key in points) {
                if (key === 'firstRow') {
                    y = H / 2 - 150;
                } 
                else if (key === 'secondRow') {
                    y = H / 2 - 100;
                } else if (key === 'thirdRow') {
                    y = H / 2 - 50;
                } 
                else if (key === 'fourthRow') {
                    y = H / 2;
                } else if (key === 'fifthRow') {
                    y = H / 2 + 50;
                } else if (key === 'sixthRow') {
                    y = H / 2 + 100;
                } else if (key === 'seventhRow') {
                    y = H / 2 + 150;
                }
                for (x = 50; x < W - 50; x += 40) {
                    points[key].push({
                        oldX: x,
                        oldY: y,
                        x: x,
                        y: y,
                        vx: 0,
                        vy: 0,
                        px: x - 70,
                        py: y
                    });
                }
            }
        }
        generatePoints(100);

        function movePoints() {
            ctx.save();
            var dx, dy, dist, curve, switcher = 0;
            for (var key in points) {
                ctx.beginPath();
                ctx.moveTo(points[key][0].x, points[key][0].y);
                points[key].forEach(function(p) {
                    dx = ball1.x - p.x;
                    dy = ball1.y - p.y;
                    dist = Math.sqrt(dx * dx + dy * dy);

                    if (dist < 200) {
                        p.vx = Math.random() * 2 - 1;
                        p.vy = Math.random() * -30;
                    } else if (dist === 200) {
                        p.vx = p.vy = 0;
                    } else if (dist > 200 && dist < 300) {
                        p.vy = Math.random() * -12;
                    } else {
                        p.vx = (p.oldX - p.x) * .1;
                        p.vy = (p.oldY - p.y) * .1;
                    }
                    p.x += p.vx;
                    p.y += p.vy;
                    ctx.strokeStyle = '#fff';
                    ctx.lineTo(p.x, p.y);
                });
                ctx.stroke();
                ctx.closePath()
            }
            ctx.restore();
        }

        function moveBall(ball) {
            if (ball.x >= W - ball.radius / 2) {
                ball.x = W - ball.radius / 2;
                ball.vx *= -1;
            } else if (ball.x < 0 + ball.radius / 2) {
                ball.x = 0 + ball.radius / 2;
                ball.vx *= -1;
            }
            ball.x += ball.vx;
            ball.y += ball.vy;
        }


        // (function drawFrame() {
        //     window.requestAnimationFrame(drawFrame, canvas);
        //     ctx.fillStyle = 'transparent';
        //     ctx.fillRect(0, 0, W, H);
        //     ctx.clearRect(0, 0, W, H);
        //     movePoints();
        //     moveBall(ball1);
        // }());

        var lines=["#ffffff","#ffffff61","#ffffff21"];
        var step=0;
        function loop(){
            ctx.clearRect(0,0,W,H);
            step++;
            if(step==W){
                step=0;
            }
            // 画线
            for(var j=2;j>=0;j--){
                ctx.strokeStyle=lines[j];
                var angle=(step+j*45)*Math.PI/180;
                var deltaHeight=Math.sin(angle)*50;
                var deltaHeightRight=Math.cos(angle)*50;
                ctx.beginPath();
                ctx.moveTo(0,H/2+deltaHeight+50);
                ctx.bezierCurveTo(
                    W/2,H/2+deltaHeight+50,W/2,H/2+deltaHeight+50,W,H/2+deltaHeightRight+50
                );
                ctx.stroke();
            }
                requestAnimationFrame(loop);
        }
        loop();

})
</script>
</html>